"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _utils = require("../../utils");

var _skuHelper = require("../utils/skuHelper");

var _createNamespace = (0, _utils.createNamespace)('sku-row-item'),
    createComponent = _createNamespace[0];

var _default2 = createComponent({
    props: {
        skuValue: Object,
        skuKeyStr: String,
        skuEventBus: Object,
        selectedSku: Object,
        skuList: {
            type: Array,
            default: function _default() {
                return [];
            }
        }
    },
    computed: {
        choosable: function choosable() {
            return (0, _skuHelper.isSkuChoosable)(this.skuList, this.selectedSku, {
                key: this.skuKeyStr,
                valueId: this.skuValue.id
            });
        }
    },
    methods: {
        onSelect: function onSelect() {
            if (this.choosable) {
                this.skuEventBus.$emit('sku:select', (0, _extends2.default)({}, this.skuValue, {
                    skuKeyStr: this.skuKeyStr
                }));
            }
        }
    },
    render: function render() {
        var h = arguments[0];
        var choosed = this.skuValue.id === this.selectedSku[this.skuKeyStr];
        var imgUrl = this.skuValue.imgUrl || this.skuValue.img_url;
        return h("span", {
            "class": ['van-sku-row__item', {
                'van-sku-row__item--active': choosed,
                'van-sku-row__item--disabled': !this.choosable
            }],
            "on": {
                "click": this.onSelect
            }
        }, [imgUrl && h("img", {
            "class": "van-sku-row__item-img",
            "attrs": {
                "src": imgUrl
            }
        }), h("span", {
            "class": "van-sku-row__item-name"
        }, [this.skuValue.name])]);
    }
});

exports.default = _default2;